//
//  UIButton+Chain.m
//  ditelMaintain
//
//  Created by 葛悦彣 on 2023/3/2.
//

#import "UIButton+Chain.h"

@implementation UIButton (Chain)

+ (UIButton * _Nonnull (^)(UIButtonType))newButton {
    return ^(UIButtonType type){
        return [UIButton buttonWithType:type];
    };
}

-(UIButton * _Nonnull (^)(NSString * _Nonnull, UIControlState))addText {
    return ^(NSString * text,UIControlState state){
        [self setTitle:text forState:state];
        return self;
    };
}

-(UIButton * _Nonnull (^)(NSString * _Nonnull))addNormalText {
    return ^(NSString * text){
        [self setTitle:text forState:UIControlStateNormal];
        return self;
    };
}

- (UIButton * _Nonnull (^)(UIColor * _Nonnull))addNormalColor {
    return ^(UIColor * textColor){
        [self setTitleColor:textColor forState:UIControlStateNormal];
        return self;
    };
}

- (UIButton * _Nonnull (^)(UIFont * _Nonnull))addFont {
    return ^(UIFont * font){
        self.titleLabel.font = font;
        return self;
    };
}


- (UIButton * _Nonnull (^)(id ,SEL ))addTarget {
    return ^(id target,SEL sel){
        [self addTarget:target action:sel forControlEvents:UIControlEventTouchUpInside];
        return self;
    };
}

- (UIButton * _Nonnull (^)(UIImage * _Nonnull))addimg{
    return ^(UIImage * img){
        [self setImage:img forState:UIControlStateNormal];
        [self setImage:img forState:UIControlStateHighlighted];
        return self;
    };
}

- (UIButton * _Nonnull (^)(UIImage * _Nonnull))addBackgroundimg{
    return ^(UIImage * img){
        [self setBackgroundImage:img forState:UIControlStateNormal];
        [self setBackgroundImage:img forState:UIControlStateHighlighted];
        return self;
        
    };
}


- (UIButton * _Nonnull (^)(UIColor * _Nonnull))addbackgroundColor{
    return ^(UIColor * color){
        self.backgroundColor = color;
        return self;
    };
}

- (UIButton *  _Nonnull (^)(CGFloat))addYJ{
    return ^(CGFloat a){
        self.layer.cornerRadius = a;
        self.layer.masksToBounds = YES;
        return self;
    };
}

@end
